#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#

import configparser

config = configparser.ConfigParser()
config.read("jdbc.cfg")

print(config.sections())
# 删除
config.remove_section("conf2")
config.remove_option("conf1", "version")  # remove_option(self, section, option)

# 判断是否存在
print(config.has_section("conf2"))  # False  判断是否存在
print(config.has_option("conf1", "pwd"))  # True  判断标题下的这个key是否存在

# 添加
config.add_section("con3")
config.set("con3", "user", "conf3")  # set(self, section, option, value=None)
config.set("con3", "pwd", "321")  # set(self, section, option, value=None)

print(config.sections())
print(config.items("conf1"))
print(config.items("con3"))     # [('user', 'conf3'), ('pwd', '321')]

config.write(open("jdbc.cfg","w"))